﻿using System.Collections.Generic;
using System.Linq;
using InnovTech.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace InnovTech.Util.Test.Data
{
    /// <summary>
    /// Summary description for TestWeakRefList
    /// </summary>
    [TestClass]
    public class TestWeakRefList
    {
        public TestWeakRefList()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestMethod1()
        {
            List<int> dic = new List<int> { 1, 2, 3, 4, 5 };
            WeakRefList<int> list = new WeakRefList<int>(10);
            list.AddRange(dic);
            Assert.AreEqual(dic.Count, list.Count);
            list.Remove(1);
            Assert.AreEqual(dic.Count - 1, list.Count);
            list.RemoveAll(x => x < 4);
            Assert.AreEqual(2, list.Count);
            int ro = list.GetRefObject(y => y > 4);
            Assert.AreEqual(5, ro);
            Assert.AreEqual(2, list.GetRefObjects(w => w > 3).Count());
            Assert.IsFalse(list.Contains(2));
            Assert.IsTrue(list.Contains(5));
        }
    }
}
